<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								终端编号：<input type="text" name="tid" id="tid"/>
							</li>

							<li>
								所属分组：<input type="text" name="aname"/>
							</li>

							<li>
								终端名称：<input type="text" name="tname"/>
							</li>

							<li>
								流量使用范围：<input type="text" name="minNum" placeholder="最小值" style="width:100px" />MB ~ <input type="text" name="maxNum" placeholder="最大值"  style="width:100px" />MB
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="broad:traffic:add">-->
					<!--<i class="fa fa-plus"></i> 添加-->
				<!--</a>-->
				<!--<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="broad:traffic:edit">
					<i class="fa fa-edit"></i> 设置终端流量限制
				</a>-->
				<!--<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="broad:traffic:remove">
					<i class="fa fa-remove"></i> 批量设置流量限制
				</a>-->
                <input type="text" name="rdsNum" id="rdsNum" width="50px"/>
                <a class="btn btn-info btn-del disabled" onclick="rdsSet()">
                     批量设置限制流量/MB
                </a>
				<!--<input type="text" name="fmfrequencyNum" id="fmfrequencyNum" width="50px"/>-->
				<!--<a class="btn btn-warning btn-del disabled" onclick="fmfrequency()">-->
					<!--批量设置限终端启用-->
				<!--</a>-->
				<!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="broad:traffic:export">-->
						<!--<i class="fa fa-download"></i> 导出-->
				 <!--</a>-->
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('broad:traffic:edit')}]];
        var removeFlag = [[${@permission.hasPermi('broad:traffic:remove')}]];
		var datas = [[${@dict.getType('sys_traffic_status')}]];
		var data2s = [[${@dict.getType('sys_tem_staus')}]];
        var prefix = ctx + "broad/traffic";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                rdsSetUrl: prefix + "/rdsSet",
				fmfrequencyUrl: prefix + "/fmfrequencySet",
                modalName: "流量",
				search: false,
		        showExport: true,
                columns: [
                    {
		            checkbox: true
		        },
				{
					field : 'tid',
					title : '终端流量使用信息表编号',
					visible: false
				},
				{
					field : 'tid', 
					title : '终端编号',
					sortable: true
				},
					{
						field : 'tname',
						title : '终端名称',
						sortable: true
					},
					{
						field : 'aname',
						title : '所属分组',
						sortable: true
					},
					{
						field : 'uname',
						title : '上级分组',
						sortable: true
					},
//				{
//					field : 'usetraffic',
//					title : '使用流量/MB',
//					sortable: true,
//					formatter: function(value, row, index) {
//						var sd = row.sd.substr(0,row.sd.indexOf("M"));
//						var sdf = row.sdf.substr(0,row.sdf.indexOf("M"));
//						return Number(sd)-Number(sdf);
//					}
//				},
				{
					field : 'trafficlimit',
					title : '流量限制/MB',
					sortable: true
				},
				{
					field: 'trafficlimit',
					title: '状态',
					align: 'center',
					formatter: function(value, row, index) {
                        if (value > 0)
                            return '<a class="btn btn-xs btn-primary" >正常</a>';
                        else
                            return '<a class="btn btn-xs btn-danger" >超量</a>';
					}
				},
				{
					field : 'lasttime', 
					title : '流量统计时间',
					sortable: true
				},
				{
					field: 'trafficlimit',
					title: '启用状态',
					sortable: true,
					formatter: function (value, row, index) {
						if (value > 0)
							return '<a class="btn btn-xs btn-primary" >启用</a>';
						else
							return '<a class="btn btn-xs btn-danger" >停用</a>';
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	// actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.ttid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.ttid + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }
		        ]
            };
            $.table.init(options);
        });

        function rdsSet() {
            var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要更加选中的" + rows.length + "条数据的限制流量吗?", function() {
                var url = $.table._option.rdsSetUrl;
                var rdsNumber = document.getElementById("rdsNum").value;
                var data = {"ids": rows.join(),"number": rdsNumber};
                $.operate.submit(url, "post", "json", data);
            });
        }
		function fmfrequency() {
			var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.confirm("确认要更加选中的" + rows.length + "条数据的终端启用吗?", function() {
				var url = $.table._option.fmfrequencyUrl;
				var fmfrequencyNumber = document.getElementById("#fmfrequencyNum").value;
				var data = {"ids": rows.join(),"number": fmfrequencyNumber};
				$.operate.submit(url, "post", "json", data);
			});
		}
        String.prototype.trim=function(){
            return this.replace(/(^\s*)|(\s*$)/g, "");
        }
        $("#tid").change(function(){
            $(this).val($(this).val().trim());
        });

	</script>
</body>
</html>